/*     */ package openmyexplorer.actions;
/*     */ 
/*     */ import java.io.IOException;

/*     */ import org.eclipse.core.resources.IFile;
/*     */ import org.eclipse.core.resources.IResource;
/*     */ import org.eclipse.jdt.core.IJavaElement;
/*     */ import org.eclipse.jface.action.IAction;
/*     */ import org.eclipse.jface.dialogs.MessageDialog;
/*     */ import org.eclipse.jface.text.ITextSelection;
/*     */ import org.eclipse.jface.util.IPropertyChangeListener;
/*     */ import org.eclipse.jface.util.PropertyChangeEvent;
/*     */ import org.eclipse.jface.viewers.ISelection;
/*     */ import org.eclipse.jface.viewers.IStructuredSelection;
/*     */ import org.eclipse.jface.viewers.ITreeSelection;
/*     */ import org.eclipse.jface.viewers.TreePath;
/*     */ import org.eclipse.swt.widgets.Shell;
/*     */ import org.eclipse.ui.IActionDelegate;
/*     */ import org.eclipse.ui.IEditorPart;
/*     */ import org.eclipse.ui.IWorkbenchWindow;
/*     */ import org.eclipse.ui.PlatformUI;

import openmyexplorer.Activator;
import openmyexplorer.util.Messages;
import openmyexplorer.util.OperatingSystem;
/*     */ 
/*     */ public abstract class AbstractOpenExplorerAction
/*     */   implements IActionDelegate, IPropertyChangeListener
/*     */ {
/*  57 */   protected IWorkbenchWindow window = PlatformUI.getWorkbench()
/*  57 */     .getActiveWorkbenchWindow();
/*     */   protected Shell shell;
/*     */   protected ISelection currentSelection;
/*     */   protected String systemBrowser;
/*     */ 
/*     */   public AbstractOpenExplorerAction()
/*     */   {
/*  64 */     this.systemBrowser = OperatingSystem.INSTANCE.getSystemBrowser();
/*  65 */     Activator.getDefault().getPreferenceStore()
/*  66 */       .addPropertyChangeListener(this);
/*     */   }
/*     */ 
/*     */   public void propertyChange(PropertyChangeEvent event)
/*     */   {
/*  77 */     if (OperatingSystem.INSTANCE.isLinux())
/*  78 */       this.systemBrowser = OperatingSystem.INSTANCE.getSystemBrowser();
/*     */   }
/*     */ 
/*     */   public void run(IAction action)
/*     */   {
/*  83 */     if ((this.currentSelection == null) || (this.currentSelection.isEmpty())) {
/*  84 */       return;
/*     */     }
/*  86 */     if ((this.currentSelection instanceof ITreeSelection)) {
/*  87 */       ITreeSelection treeSelection = (ITreeSelection)this.currentSelection;
/*     */ 
/*  89 */       TreePath[] paths = treeSelection.getPaths();
/*     */ 
/*  91 */       for (int i = 0; i < paths.length; i++) {
/*  92 */         TreePath path = paths[i];
/*  93 */         IResource resource = null;
/*  94 */         Object segment = path.getLastSegment();
/*  95 */         if ((segment instanceof IResource))
/*  96 */           resource = (IResource)segment;
/*  97 */         else if ((segment instanceof IJavaElement)) {
/*  98 */           resource = ((IJavaElement)segment).getResource();
/*     */         }
/* 100 */         if (resource != null)
/*     */         {
/* 103 */           String browser = this.systemBrowser;
/* 104 */           String location = resource.getLocation().toOSString();
/* 105 */           if ((resource instanceof IFile)) {
/* 106 */             location = ((IFile)resource).getParent().getLocation()
/* 107 */               .toOSString();
/* 108 */             if (OperatingSystem.INSTANCE.isWindows()) {
/* 109 */               browser = this.systemBrowser + " /select,";
/* 110 */               location = ((IFile)resource).getLocation()
/* 111 */                 .toOSString();
/*     */             }
/*     */           }
/* 114 */           openInBrowser(browser, location);
/*     */         }
/*     */       } } else if (((this.currentSelection instanceof ITextSelection)) || 
/* 117 */       ((this.currentSelection instanceof IStructuredSelection)))
/*     */     {
/* 119 */       IEditorPart editor = this.window.getActivePage().getActiveEditor();
/* 120 */       if (editor != null) {
/* 121 */         IFile current_editing_file = (IFile)editor.getEditorInput()
/* 122 */           .getAdapter(IFile.class);
/* 123 */         String browser = this.systemBrowser;
/* 124 */         String location = current_editing_file.getParent()
/* 125 */           .getLocation().toOSString();
/* 126 */         if (OperatingSystem.INSTANCE.isWindows()) {
/* 127 */           browser = this.systemBrowser + " /select,";
/* 128 */           location = current_editing_file.getLocation().toOSString();
/*     */         }
/* 130 */         openInBrowser(browser, location);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void openInBrowser(String browser, String location) {
/*     */     try {
/* 137 */       if (OperatingSystem.INSTANCE.isWindows())
/* 138 */         Runtime.getRuntime().exec(browser + " \"" + location + "\"");
/*     */       else
/* 140 */         Runtime.getRuntime().exec(new String[] { browser, location });
/*     */     }
/*     */     catch (IOException e) {
/* 143 */       MessageDialog.openError(this.shell, Messages.OpenExploer_Error, 
/* 144 */         Messages.Cant_Open + " \"" + location + "\"");
/* 145 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void selectionChanged(IAction action, ISelection selection) {
/* 150 */     this.currentSelection = selection;
/*     */   }
/*     */ }

/* Location:           F:\Eclipse2020\eclipse\dropins\OpenExplorer_1.5.0.v201108051513.jar
 * Qualified Name:     openexplorer.actions.AbstractOpenExplorerAction
 * JD-Core Version:    0.6.2
 */